library SelectNCCommand initializer init requires LegacySystem, PlayerSelectsHeroCommand, LegacyHumanAbilities


	private function Trig_Player_Selects_NC_Conditions takes nothing returns boolean
		if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'H002' ) ) then
			return false
		endif
		return true
	endfunction


	private function Trig_Player_Selects_NC_Actions takes nothing returns nothing

		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer id = GetConvertedPlayerId(p)

		call putUnit(p,"hero", u)

		call setPlayerDataInteger(p,"pistol_ammo",15)
		call setPlayerDataInteger(p,"pistol_type",2)
		call setPlayerDataBoolean(p,"pistol_reload",false)

		call SetUnitUserData(u,50)
		
		set udg_HeroAvailable[5] = udg_HeroAvailable[5] - 1
		 
		call putInteger(null,"NumCorpsman", (getInteger(null,"NumCorpsman") + 1))
		
		set udg_PlayerIcon[id] = "ReplaceableTextures\\CommandButtons\\BTN_Unit_Medic.blp"
	   
		call UnitAddItemById(u,'I004')

		set udg_KillFactor[id] = 1.7   
		set udg_ReloadTime[id] = 5.0
		
		call AddPrimaryAmmo(u, 15, 50)
		call RegisterAmmoAutoReloadListener(u)
		call RegisterAmmoEmptyListener(u)
		call InitHero(u)
		if GetI("player mos", id) == 2 then
			call ModifyHeroSkillPoints( u, bj_MODIFYMETHOD_ADD, 1 )
		endif
		
		set u = null
		set p = null
		

		
		if( udg_HeroAvailable[5] <= 0 ) then
			call DestroyTrigger(GetTriggeringTrigger())
		endif

	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterEnterRectSimple( t, GetPlayableMapRect() )
		call TriggerAddCondition( t, Condition( function Trig_Player_Selects_NC_Conditions ) )
		call TriggerAddAction( t, function Trig_Player_Selects_NC_Actions )
	endfunction

endlibrary